package com.lcsolute.miniapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lcsolute.miniapi.dao.VideoDao;

import com.lcsolute.miniapi.domain.ResponseResult;
import com.lcsolute.miniapi.domain.entity.Video;
import com.lcsolute.miniapi.service.VideoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Videos)表服务实现类
 *
 * @author makejava
 * @since 2022-02-19 04:04:17
 */
@Service("videosService")
public class VideoServiceImpl extends ServiceImpl<VideoDao, Video> implements VideoService {
    @Override
    public ResponseResult hotVedioList() {
        LambdaQueryWrapper<Video> queryWrapper = new LambdaQueryWrapper<>();
        // 正式发布的视频
        queryWrapper.eq(Video::getStatus, 1);
        // 安装点赞量进行排序
        queryWrapper.orderByDesc(Video::getLikeCounts);
        // 最多只查询 10 条
        Page<Video> page = new Page<>(1, 10);
        page(page, queryWrapper);

        List<Video> videos = page.getRecords();
        return ResponseResult.okResult(videos);
    }
}
